home *** CD-ROM | disk | FTP | other *** search
/ The X-Philes (2nd Revision) / The X-Philes Number 1 (1995).iso / xphiles / hp48_2 / read.ir < prev    next >
Text File  |  1991-04-12  |  3KB  |  158 lines

  1. Article 2701 of comp.sys.handhelds:
  2. Path: en.ecn.purdue.edu!noose.ecn.purdue.edu!samsung!uunet!snorkelwacker.mit.edu!apple!agate!shelby!msi.umn.edu!noc.MR.NET!gacvx2.gac.edu!hhdist
  3. From: erikmb@cd.chalmers.se (Erik Bryntse)
  4. Newsgroups: comp.sys.handhelds
  5. Subject: Test program that reads the IR input of HP48
  6. Message-ID: <9012031147.AA04665@cd.chalmers.se>
  7. Date: 3 Dec 90 11:46:55 GMT
  8. Lines: 142
  9. To: handhelds@gac.edu
  10. Return-path: <erikmb@cd.chalmers.se>
  11. To: handhelds@gac.edu
  12. X-Mailer: ELM [version 2.3 PL8]
  13.  
  14.  
  15. Hello!
  16.  
  17. Since there are many people that are interested in having their 48's 
  18. as learning remote controls, I am posting a little test program I 
  19. wrote some weeks ago.
  20.  
  21. It reads the IR input diode, and times each period (at the low-high 
  22. transition). The result is returned as a string.
  23.  
  24. This is only intended to help if someone out there is struggling to 
  25. make a remote control program for the 48, so I only include the source 
  26. code. It is not very well commented (remember it's a test program...).
  27.  
  28. Hope this helps someone!
  29.  
  30. Erik Bryntse
  31.  
  32. erikmb@cd.chalmers.se
  33.  
  34.  
  35. ; ---- source code begins here ----
  36.  
  37. SaveR:=#679B
  38. LoadR:=#67D2    
  39. DispOff:=#1BBD
  40. DispOn:=#1B8F
  41.  
  42.  
  43. ; Test program that reads the IR-diode
  44. ; Written by Erik Bryntse
  45. ; Returns 1: "string" that contains 3 nibbles per period time
  46. ; Parts taken from INPRT by William C Wickes
  47.  
  48.  
  49.     call.a        SaveR        ; save RPL regs
  50.     call.a        #613E
  51.     clrb        15,ST
  52.     call.a        #6806        ; space bw RSTK & TOS -> C
  53.     move.a        c,a
  54.     move.p5        #10F,c
  55.     subn.a        a,c        ; C := space - #200
  56.     brcs        OutOfMem    ; If not enough exit
  57.  
  58.     move.w        c,r1        ; Save away in R1
  59.     call.a        #1115        ; toggles b 0 of #10E
  60.     intoff
  61.     call.a        DispOff
  62.     move.w        r1,c        ; Alloc all mem - #200 nibs
  63.     srb.a        c        ; in bytes!
  64.     call.a        #5B79        ; alloc C bytes string -> D0
  65.     move.w        r1,c
  66.     swap.a        a,d0
  67.     move.a        a,d0
  68.     add.a        c,a
  69.     move.w        a,r1        ; R1 highest allowed addr
  70.     clr.w        c
  71.     move.w        c,r4        ; R4 := 0
  72.     move.1        4,p
  73.     move.p1        #6,c        ; C := #60000
  74.     move.1        0,p
  75.     brcc        Begin        ; If alloc OK start prog
  76.     
  77. OutOfMem:
  78.     
  79.     call.a        #10E5
  80.     jump.a        #65AA        ; load regs, Out Of Mem!
  81.  
  82. ; Not out of memory error
  83.  
  84. Begin:    call.3        MainProc
  85.     call.a        #16671
  86.     move.5        #10B,d1
  87.     move.b        @d1,c
  88.     clrb        #5,c
  89.     move.b        c,@d1        ; clrb 5 of #10B
  90.     call.a        DispOn
  91.     call.a        #10E5
  92.     move.w        r0,a
  93.     call.a        #54266
  94.     move.a        @d0,a
  95.     add.a        5,d0
  96.     jump        @a        ; bye bye
  97.     
  98. ;========================================================
  99.  
  100. MainProc:
  101.  
  102.     call.3        Wait1st        ; Wait until IR toggle or timeout
  103.     retcs                ; Timeout: return
  104.  
  105. OneMor:    
  106.  
  107.     move.x        a,@d0        ; Store period time in string (3 nibs)
  108.     add.a        3,d0
  109.     swap.a        a,d0
  110.     move.a        a,d0
  111.     move.a        r1,c
  112.     retle.a        c,a
  113.     clr.a        a
  114.     call.3        WaitL        ; Time one more pulse
  115.     brcc        OneMor
  116.  
  117.     retclrc                ; Timeout
  118.  
  119.  
  120. ; Wait until first IR pulse is received
  121.  
  122. Wait1st:
  123.  
  124.     clr.w        a
  125.     move.p5        #20000,c    ; Timeout counter
  126.     move.5        #0011A,d1
  127. NoIR:    dec.a        c
  128.     brcs        TimeOut
  129.     move.s        @d1,c
  130.     add.s        c,c
  131.     brcc        NoIR        ; Wait until first IR pulse recvd
  132.  
  133. ; Wait until IR goes low
  134.  
  135. WaitL:    inc.x        a
  136.     retcs
  137.     move.s        @d1,c
  138.     add.s        c,c
  139.     brcs        WaitL        ; Wait until bit 3 of 11A low
  140.  
  141. ; Wait until IR goes high again
  142.  
  143. WaitH:    inc.x        a
  144.     retcs
  145.     move.s        @d1,c
  146.     add.s        c,c
  147.     brcc        WaitH        ; Wait until bit 3 of 11A high
  148.     retclrc
  149.  
  150. TimeOut:
  151.     
  152.     pop.a        c
  153.     retsetc
  154.  
  155. ; ---- souce code ends here ----    
  156.  
  157.  
  158.